{% extends "base.html" %}

{% block content %}
    <h1 class="mb-4 text-center">
        {% if search_keyword %}
            搜索结果: {{ search_keyword }}
        {% elif current_category %}
            {{ current_category }}
        {% else %}
            最新发布的商品
        {% endif %}
    </h1>
    
    <div class="row">
        {% if items %}
            {% for item in items %}
                <div class="col-md-4">
                    <div class="card">
                        {% if item.image %}
                            <img src="{{ url_for('static', filename=item.image) }}" class="card-img-top" alt="{{ item.name }}">
                        {% else %}
                            <img src="https://via.placeholder.com/400x200?text=暂无图片" class="card-img-top" alt="暂无图片">
                        {% endif %}
                        <div class="card-body">
                            <h5 class="card-title">{{ item.name }}</h5>
                            <p class="card-text text-danger font-weight-bold" style="font-size: 1.2rem;">¥{{ item.price }}</p>
                            <p class="card-text" style="max-height: 60px; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;">{{ item.description }}</p>
                            <div class="mt-3">
                                <span class="badge bg-secondary">{{ item.category }}</span>
                                <span class="badge bg-info ms-2">联系方式: {{ item.contact }}</span>
                            </div>
                        </div>
                    </div>
                </div>
            {% endfor %}
        {% else %}
            <div class="col-12 text-center">
                <h3 class="text-muted">暂无商品信息</h3>
            </div>
        {% endif %}
    </div>
{% endblock %}